//
//  V4InputBuyerAndSeller.m
//  XinKaiFa55like
//
//  Created by 55like on 25/09/2017.
//  Copyright © 2017 55like lj. All rights reserved.
//

#import "BuyerAndSellerDetailViewController.h"
#import "MyUiIAlertView.h"
#import "MyUiActionSheet.h"
#import "SelectTitleViewController.h"
#import "PLTextView.h"
#import "ImageSelectEditorView.h"
#import "WSButtonGroup.h"
#import "NavigationBarToggleTabView.h"
#import "RHTableView.h"
#import "LFImagePickerController.h"
#import <Photos/Photos.h>
#import "AddImageView.h"
@interface BuyerAndSellerDetailViewController ()<UITextFieldDelegate,UITextViewDelegate,LFImagePickerControllerDelegate>
{
    WSButtonGroup*_btnGroup;
    UIScrollView*scrollView;
    //---------------v4--------------
    NavigationBarToggleTabView *toggleTab;
    
    
    UIImagePickerController *ipc;
    
}
@property(nonatomic,strong)AddImageView*  imageEditorV;
@property(nonatomic,weak)PLTextView*tv;
@property(nonatomic,strong)NSDictionary*DataDic;
@property(nonatomic,strong)UIView*view1;
@property(nonatomic,strong)UIView*view2;

@property(nonatomic,strong)RHTableView*mtableView;
@property (nonatomic,strong)NSMutableArray * imageViewArr;
@property (nonatomic,strong)NSMutableArray * imageArray;
@property (nonatomic,strong)NSMutableArray * pathArray;
@property (nonatomic,strong)NSMutableArray * remArray;
//@property(nonatomic,copy)NSString*celltitle;
@property(nonatomic,strong)UIView*viewlastInput;
@property(nonatomic,strong)UITextField*transRecordTf;
@property(nonatomic,assign)BOOL canEdite;
@end

@implementation BuyerAndSellerDetailViewController
#pragma mark  开始
- (void)viewDidLoad {
    [super viewDidLoad];
    _canEdite=YES;
//    _celltitle=@"BuyerAndSellerDetailViewControllerBuyerAndSellerDetailViewControllerBuyerAndSellerDetailViewController";
    
        [self loadDATA];

    
}
#pragma mark -  写UI

-(void)initNavTopButtons{
    toggleTab=[[NavigationBarToggleTabView alloc] initWithFrame:CGRectMake((kScreenWidth-150)/2, 28, 150, 28)];
    [self.navView addSubview:toggleTab];
    
    [self refreshNavTopButtonsData];
}
-(void)refreshNavTopButtonsData{
    __weak __typeof(self) weakSelf = self;
//    __weak RHTableView *weakTable1=_mtableView;
    //    __weak RHTableView *weakTable2=_mtableView2;
    
    NSString*titleStr=[[self.DataDic objectForJSONKey:@"type"] isEqualToString:@"1"]?@"买家详情":@"卖家详情";
    
    [toggleTab setTiltelArray:@[@{@"title":@"跟踪记录",@"id":@"products"},@{@"title":titleStr,@"id":@"news"}] toggleTab:^(NSDictionary *dicSelect) {
        if ([[dicSelect valueForJSONStrKey:@"id"] isEqualToString:@"products"]) {
            weakSelf.view1.hidden=NO;
            weakSelf.view2.hidden=YES;
        }else{
            weakSelf.view1.hidden=YES;
            weakSelf.view2.hidden=NO;
            
        }
        
    }];
}
-(void)addView2{
    
    UIView*view1=[RHMethods viewWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kScreenHeight-kTopHeight) backgroundcolor:nil superView:self.view];
    _view1=view1;
    _mtableView =[[RHTableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-kTopHeight-44) style:UITableViewStylePlain];
//    _view1=_mtableView;
    
    _mtableView.delegate = self;
    _mtableView.dataSource = self;
    _mtableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _mtableView.delegate2=self;
    //    [_mtableView registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"NewsTableViewCell"];
//    _mtableView.dataArray=[NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@"",@""]];
//    
    [_view1 addSubview:_mtableView];
    
    
    {
    UIView*viewlastInput=[RHMethods viewWithFrame:CGRectMake(0, 0, kScreenWidth, 44) backgroundcolor:rgb(244,244,244) superView:_view1];
        viewlastInput.frameBY=0;
        _viewlastInput=viewlastInput;
        UIView*viewsubinput=[RHMethods viewWithFrame:CGRectMake(10, 7, kScreenWidth-10-47, 30) backgroundcolor:nil superView:viewlastInput];
        viewsubinput.layer.borderColor=rgb(214,214,214).CGColor;
        viewsubinput.layer.borderWidth=1;
        viewsubinput.layer.cornerRadius=3;
        UITextField*tf1=[RHMethods textFieldlWithFrame:CGRectMake(10, 0, viewsubinput.frameWidth-20, viewsubinput.frameHeight) font:Font(14) color:nil placeholder:@"评论" text:@""];
        [viewsubinput addSubview:tf1];
        _transRecordTf=tf1;
        tf1.delegate=self;
        WSSizeButton*btnAdd=[RHMethods buttonWithframe:CGRectMake(viewsubinput.frameXW, 0, kScreenWidth-viewsubinput.frameWidth, 44) backgroundColor:nil text:@"" font:0 textColor:nil radius:0 superview:viewlastInput];
        [btnAdd setImage:[UIImage imageNamed:@"jiaicon"] forState:UIControlStateNormal];
        [btnAdd setBtnImageViewFrame:CGRectMake(10, (btnAdd.frameHeight-30)/2, 30, 30)];
        [btnAdd addTarget:self action:@selector(addTransRecordWithImage:) forControlEvents:UIControlEventTouchUpInside];
        
    
    }

    

}
-(void)addTransRecord:(UIButton*)btn{
    krequestParam
    if (![_transRecordTf.text notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请填写内容"];
        return;
    }
    [dictparam setObject:[self.otherInfo objectForJSONKey:@"id"] forKey:@"cuid"];
    [dictparam setObject:_transRecordTf.text forKey:@"descr"];
    
    [NetEngine createPostAction:@"customer/updatetrack" withParams:dictparam onCompletion:^(id resData, BOOL isCache) {
        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
            NSDictionary *dic=[resData getSafeObjWithkey:@"data"];
                    if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
                        [self request];
                        _transRecordTf.text = @"";
                    }else{
                        [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
                    }
            //            [self addView];
            
        }else{
            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
            
        }
    }];
    
    
}
#pragma mark  添加图片
-(void)addTransRecordWithImage:(UIButton*)btn{

//    [NetEngine uploadAllFileAction:@"customer/updatetrack" withParams:dictparam fileArray:[NSMutableArray new] onCompletion:^(id resData, BOOL isCache) {
//        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
//            [self request];
//        }else{
//            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
//        }
//    } onError:^(NSError *error) {
//        
//    } withMask:SVProgressHUDMaskTypeBlack];
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"选择图片" message:nil preferredStyle: UIAlertControllerStyleActionSheet];
    UIAlertAction *CameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *mediaType = AVMediaTypeVideo;
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
        if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
            if (!app_Name) {
                app_Name = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
            }
            [[Utility Share] showAccessPermissionsAlertViewMessage:[NSString stringWithFormat:@"‘%@’没有访问相机的权限，请前往【设置】允许‘%@’访问",app_Name,app_Name]];
            return;
        }
        
        if (!ipc) {
            ipc=[[UIImagePickerController alloc]init];
        }
        //判断当前相机是否可用
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {// 打开相机
            ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
            //设置是否可编辑
            ipc.allowsEditing = NO;
            ipc.delegate=self;
            //打开
            [self presentViewController:ipc animated:YES completion:^{
                [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault];
            }];
        }else
        {
            //如果不可用
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"设备相机不能使用..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];
            [alert show];
        }
    }];
    UIAlertAction *PhotoLibraryAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        LFImagePickerController *imagePicker = [[LFImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
        imagePicker.allowTakePicture = NO;
        imagePicker.allowPickingVideo = NO;
        imagePicker.doneBtnTitleStr = @"完成";
        imagePicker.allowEditting = NO;
        [self  presentViewController:imagePicker animated:YES completion:nil];
        
    }];
    [alertController addAction:CameraAction];
    [alertController addAction:PhotoLibraryAction];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
    

    
}

#pragma mark LFImagePickerControllerDelegate
- (void)lf_imagePickerController:(LFImagePickerController *)picker didFinishPickingThumbnailImages:(NSArray<UIImage *> *)thumbnailImages originalImages:(NSArray<UIImage *> *)originalImages infos:(NSArray<NSDictionary *> *)infos
{
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
    NSString *thumbnailFilePath = [documentPath stringByAppendingPathComponent:@"thumbnail"];
    NSString *originalFilePath = [documentPath stringByAppendingPathComponent:@"original"];
    
    NSFileManager *fileManager = [NSFileManager new];
    if (![fileManager fileExistsAtPath:thumbnailFilePath])
    {
        [fileManager createDirectoryAtPath:thumbnailFilePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    if (![fileManager fileExistsAtPath:originalFilePath])
    {
        [fileManager createDirectoryAtPath:originalFilePath withIntermediateDirectories:YES attributes:nil error:nil];
    }
    
//    for (NSInteger i = 0; i < originalImages.count; i++) {
//        //        UIImage *thumbnailImage = thumbnailImages[i];
//        UIImage *image = originalImages[i];
//        //        NSDictionary *info = infos[i];
//        //        NSString *name = [NSString stringWithFormat:@"%@.jpeg", info[kImageInfoFileName]];
////        [self addImageViews:image dataUrl:nil];
//    }
////    [self loadRefrshImageViewData];
    [self uptransImage:originalImages];
}
#pragma mark - 选择照片
//设备协议
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    DLog(@"_____info:%@",info);
    UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
    
    CGSize size =  image.size ;
    CGFloat fullW = kScreenWidth*2;
    CGFloat fullH = kScreenHeight*2;
    CGFloat ratio = MIN(fullW / size.width, fullH / size.height);
    ratio = ratio>1?1:ratio;
    CGFloat W = ratio * size.width;
    CGFloat H = ratio * size.height;
    
    //处理图片
    UIImage *logo=[[Utility Share] imageWithImageSimple:image scaledToSize:CGSizeMake(W, H)];
    // NSData *imgData=UIImageJPEGRepresentation(logo, 1.0);
   
    [self dismissViewControllerAnimated:YES completion:^{
         [self uptransImage:@[logo]];
    }];
    
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}


-(void)uptransImage:(NSArray*)tpArray{

    NSMutableArray *marry=  [NSMutableArray array];
    
    for (int i=0; i<tpArray.count; i++) {
        UIImage *image=tpArray[i];
        //    NSMutableArray *marry;
       
        NSMutableDictionary*dic=[NSMutableDictionary dictionary];
        [dic setValue:[NSString stringWithFormat:@"name%d.jpeg",i] forKey:@"fileName"];
        [dic setValue:[NSString stringWithFormat:@"%@[]",@"path"] forKey:@"fileKey"];
        NSData *imgData=UIImageJPEGRepresentation(image, 1.0);
        [dic setObject:imgData forKey:@"fileData"];
        [dic setValue:@"image" forKey:@"fileType"];
        [marry addObject:dic];
    }
    
    krequestParam
   
    [dictparam setObject:[self.otherInfo objectForJSONKey:@"id"] forKey:@"cuid"];
//    [dictparam setObject:_transRecordTf.text forKey:@"descr"];
    
        [NetEngine uploadAllFileAction:@"customer/updatetrack" withParams:dictparam fileArray:marry onCompletion:^(id resData, BOOL isCache) {
            if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
                [self request];
            }else{
                [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
            }
        } onError:^(NSError *error) {
    
        } withMask:SVProgressHUDMaskTypeBlack];

}

-(void)addView{
    
    UIView*view1=[RHMethods viewWithFrame:CGRectMake(0, kTopHeight, kScreenWidth, kScreenHeight-kTopHeight) backgroundcolor:nil superView:self.view];
    _view2=view1;
    
    __weak __typeof(self) weakSelf = self;
    {
        WSSizeButton*btnpublish=[RHMethods buttonWithframe:CGRectMake(0, _view2.frameHeight-44, kScreenWidth, 44) backgroundColor:rgb(239,186,58) text:@"确定" font:17 textColor:rgb(255,255,255) radius:0 superview:_view2];
        [btnpublish addTarget:self action:@selector(OKBtnClik:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0 , kScreenWidth, kScreenHeight-kTopHeight-44)];
    [_view2 addSubview:scrollView];
    
    
    
    float myY=0.0;
    
    
    NSArray*  arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",@"issuccess",@"重点客户",@"报价",@"类型",];
    
    
    
    //    NSArray*arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",];
    for (int i=0; i<arraytitle.count; i++) {
        NSString*titleStr=arraytitle[i];
        
        UIView*view1=[self getAddValueForKey:titleStr];
        if (view1==nil) {
            view1=[RHMethods viewWithFrame:CGRectMake(0, myY, kScreenWidth, 40) backgroundcolor:zrgbwhiteColor superView:scrollView];
            [self setAddValue:view1 forKey:titleStr];
            UILabel*lb1=[RHMethods lableX:10 Y:13 W:0 Height:14 font:14 superview:view1 withColor:nil text:titleStr];
            UITextField*tf1=[RHMethods textFieldlWithFrame:CGRectMake(100, 0, kScreenWidth-110, view1.frameHeight) font:Font(14) color:nil placeholder:@"请输入" text:@""];
            tf1.delegate=self;
            [view1 addSubview:tf1];
            tf1.textAlignment=NSTextAlignmentRight;
            WSSizeButton*btn1=[RHMethods buttonWithframe:CGRectMake(0, 0, kScreenWidth, view1.frameHeight) backgroundColor:nil text:@"" font:12 textColor:rgb(51,51,51) radius:0 superview:view1];
            //        btn1.backgroundColor=rgbRedColor;
            [btn1 setImage:[UIImage imageNamed:@"xkf_searrighticon"] forState:UIControlStateNormal];
            [btn1 setImage:[UIImage imageNamed:@"xkf_xiala2"] forState:UIControlStateSelected];
            [btn1 setBtnLableFrame:CGRectMake(0, 0, btn1.frameWidth-10-15-10, btn1.frameHeight)];
            btn1.titleLabel.textAlignment=NSTextAlignmentRight;
            btn1.hidden=YES;
            [btn1 setBtnImageViewFrame:CGRectMake(btn1.frameWidth-10-15, 0.5*(btn1.frameHeight-15), 15, 15)];
            btn1.imageView.contentMode=UIViewContentModeScaleAspectFit;
            UIView*viewline=[RHMethods viewWithFrame:CGRectMake(0, view1.frameHeight-0.5, kScreenWidth, 0.5) backgroundcolor:rgb(220,220,220) superView:view1] ;
            [view1 setAddValue:btn1 forKey:@"btn1"];
            [view1 setAddValue:tf1 forKey:@"tf1"];
            [view1 setAddValue:viewline forKey:@"viewline"];
            [view1 setAddValue:lb1 forKey:@"lb1"];
            
        }
        
        UILabel*lb1=[view1 getAddValueForKey:@"lb1"];
        WSSizeButton*btn1=[view1 getAddValueForKey:@"btn1"];
        UITextField*tf1=[view1 getAddValueForKey:@"tf1"];
        //        UIView*viewline=[view1 getAddValueForKey:@"viewline"];
        __weak __typeof(btn1) weakbtn1 = btn1;
        __weak __typeof(view1) weakview1 = view1;
        
        if (_canEdite) {
            BOOL cantEdite=YES;//不可编辑
            
            NSArray*array=@[@"备注",@"跟踪者",@"issuccess",@"重点客户",@"报价",@"类型",];
            for (NSString*arstr in array) {
                if ([arstr isEqualToString:titleStr]) {
                    cantEdite=NO;
                }
            }
            if (cantEdite) {
                tf1.userInteractionEnabled=NO;
                btn1.userInteractionEnabled=NO;
                tf1.textColor=rgb(97,97,97);
                lb1.textColor=rgb(97, 97, 97);
//                btn1.imageView.hidden=YES;
                [btn1 setImage:nil forState:UIControlStateNormal];
                [btn1 setTitleColor:rgb(97, 97, 97) forState:UIControlStateNormal];
                [btn1 setBtnLableFrame:CGRectMake(0, 0, btn1.frameWidth-10, btn1.frameHeight)];
            }
           
        }
        
        
        
        if ([titleStr isEqualToString:@"姓名"]) {
            tf1.text= [_DataDic objectForKey:@"name"];
            
        }else  if ([titleStr isEqualToString:@"性别"]) {
            
            //            tf1.text= [_DataDic objectForKey:@"name"];
            if ([[_DataDic objectForJSONKey:@"sex"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"男" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"sex"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"女" forState:UIControlStateNormal];
            }
            
            
            
            btn1.hidden=NO;
            tf1.hidden=YES;
            [btn1 addViewClickBlock:^(UIView *view) {
                [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                    
                    if (buttonIndex==1) {
                        [weakview1 setAddValue:@"1" forKey:@"data"];
                        [weakbtn1 setTitle:@"男" forState:UIControlStateNormal];
                    }else if(buttonIndex==2){
                        [weakview1 setAddValue:@"2" forKey:@"data"];
                        [weakbtn1 setTitle:@"女" forState:UIControlStateNormal];
                    }
                    
                } WithTitle:@"性别" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"男",@"女",nil];
            }];
            
        }else  if ([titleStr isEqualToString:@"电话"]) {
            tf1.text= [_DataDic objectForKey:@"mobile"];
            
        }else  if ([titleStr isEqualToString:@"微信"]) {
            
            tf1.text= [_DataDic objectForKey:@"wechat"];
        }else  if ([titleStr isEqualToString:@"邮箱"]) {
            tf1.text= [_DataDic objectForKey:@"email"];
            
        }else  if ([titleStr isEqualToString:@"性质"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            if ([[_DataDic objectForJSONKey:@"nature"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"中介" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"nature"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"直客" forState:UIControlStateNormal];
            }
            
            
            [btn1 addViewClickBlock:^(UIView *view) {
                [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                    
                    if (buttonIndex==1) {
                        [weakview1 setAddValue:@"1" forKey:@"data"];
                        [weakbtn1 setTitle:@"中介" forState:UIControlStateNormal];
                    }else if(buttonIndex==2){
                        [weakview1 setAddValue:@"2" forKey:@"data"];
                        [weakbtn1 setTitle:@"直客" forState:UIControlStateNormal];
                    }
                    
                } WithTitle:@"性质" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"中介",@"直客",nil];
            }];
        }else  if ([titleStr isEqualToString:@"公司名称"]) {
            
            tf1.text= [_DataDic objectForKey:@"companyname"];
        }else  if ([titleStr isEqualToString:@"分类"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            if (_DataDic) {
                [view1 setAddValue:[_DataDic objectForJSONKey:@"cid"] forKey:@"data"];
                [btn1 setTitle:[_DataDic objectForJSONKey:@"cname"] forState:UIControlStateNormal];
            }
            
            [btn1 addViewClickBlock:^(UIView *view) {
                NSMutableDictionary*mdic=[NSMutableDictionary new];
                [mdic setObject:[NSString stringWithFormat:@"%@",weakbtn1.currentTitle] forKey:@"currentTitle"];
                
                NSMutableArray*mtitlarray=[NSMutableArray new];
                
                NSArray*array=[UTILITY.userTypeData objectForKey:@"bigcate"];
                for (NSDictionary*dic in array) {
                    for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
                        NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
                        [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
                        
                        [mtitlarray addObject:submdic];
                    }
                }
                [mdic setObject:mtitlarray forKey:@"titleArray"];
                //            __weak __typeof(btn1) weakbtn1 = btn1;
                [weakSelf pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择分类" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
                    //                weaktxtfenlie.text=[data objectForJSONKey:@"title"];
                    [weakbtn1 setTitle:[data objectForJSONKey:@"title"] forState:UIControlStateNormal];
                    [weakview1 setAddValue:[data objectForJSONKey:@"id"] forKey:@"data"];
                    
                }];
                
            }];
        }else  if ([titleStr isEqualToString:@"备注"]) {
            
            view1.userInteractionEnabled=YES;
            btn1.hidden=NO;
            //            btn1.selected=YES;
            tf1.hidden=YES;
            [btn1 addViewClickBlock:^(UIView *view) {
                UIButton*mbtn=(UIButton*)view;
                mbtn.selected=!mbtn.selected;
                UIView*viewReMark=[weakSelf getAddValueForKey:@"viewReMark"];
                if (weakbtn1.selected) {
                    weakview1.frameHeight=viewReMark.frameYH;
                    viewReMark.hidden=NO;
                }else{
                    viewReMark.hidden=YES;
                    weakview1.frameHeight=40;
                }
                [weakSelf reloadScrollView];
            }];
            {
                
                UIView*viewReMark=[self getAddValueForKey:@"viewReMark"];
                if(viewReMark==nil){
                    
                    viewReMark=[RHMethods viewWithFrame:CGRectMake(0, 40, kScreenWidth, 171) backgroundcolor:zrgbwhiteColor superView:view1];
                    
                    viewReMark.hidden=YES;
                    PLTextView*tv=[[PLTextView alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, 68)];
                    [viewReMark addSubview:tv];
                    tv.Placeholder=@"请填写备注信息";
                    tv.font=Font(14);
                    
                    _tv=tv;
                    _tv.text=[_DataDic valueForJSONStrKey:@"descr"];
                    _tv.delegate=self;
                    
                    
                    for (NSDictionary*dic in _DataDic[@"path"]) {
                        //                        NSMutableDictionary * imageData = [NSMutableDictionary new];
                        //                        [imageData setValue:[dic valueForJSONStrKey:@"id"] forKey:@"id"];
                        //                        [imageData setValue:[dic valueForJSONStrKey:@"url"] forKey:@"path"];
                        [self.imageArray addObject:[dic valueForJSONStrKey:@"url"]];
                    }
                    UIImage * image = [UIImage imageNamed:@"zdyadd"];
                    [self.imageArray addObject:image];
                    
                    AddImageView*  imageEditorV = [[AddImageView alloc] initWithFrame:CGRectMake(0,  88, kScreenWidth, ((self.imageArray.count % 4 == 0?0:1) + self.imageArray.count / 4) * (kScreenWidth - 20)/4)];
                    [viewReMark addSubview:imageEditorV];
                    _imageEditorV = imageEditorV;
                    
//                    ImageSelectEditorView*  imageEditorV=[[ImageSelectEditorView alloc] initWithFrame:CGRectMake(0,  88, kScreenWidth, 100)];
//                    _imageEditorV=imageEditorV;
//                    [viewReMark addSubview:imageEditorV];
                    __weak __typeof(viewReMark) weakviewReMark = viewReMark;
                    //                    __weak __typeof(viewReMark) weakviewReMark = viewReMark;
                    __weak __typeof(imageEditorV) wimageEditorV = imageEditorV;
                   
           
                    imageEditorV.imageArray = self.imageArray;
                    [imageEditorV reshData];
                    imageEditorV.remBlock = ^(NSInteger row) {
                        
                        
                        if (weakSelf.pathArray.count > row) {
                            
                            NSString * idd = [[weakSelf.pathArray[row] valueForJSONStrKey:@"id"] mutableCopy];
                            [weakSelf.remArray addObject:idd];
                            [weakSelf.pathArray removeObjectAtIndex:row];
                        }
                        
                    };
                    imageEditorV.imageBlock = ^(NSMutableArray *imageArr, CGFloat cH) {
                        
                        
                        weakSelf.imageArray = imageArr;
                        
                        if ([weakSelf getAddValueForKey:@"标签"]) {
                            weakviewReMark.frameHeight=wimageEditorV.frameYH+10;
                            if (weakbtn1.selected) {
                                
                                weakview1.frameHeight=weakviewReMark.frameYH;
                            }else{
                                
                                weakview1.frameHeight=40;
                            }
                            [weakSelf reloadScrollView];
                        }
                        
                    };
//                    [imageEditorV setImageUrlArray:picArray imageChange:^(NSInteger suc,CGFloat h) {
                    
                        //                        [weakSelf addView];
                        
                    
                        
//                    }];
                    
//                    imageEditorV.maxNumber=9;
//                    if ([weakSelf getAddValueForKey:@"标签"]) {
                        weakviewReMark.frameHeight=wimageEditorV.frameYH+10;
                        if (weakbtn1.selected) {
                            
                            weakview1.frameHeight=weakviewReMark.frameYH;
                        }else{
                            
                            weakview1.frameHeight=40;
                        }
                        [weakSelf reloadScrollView];
//                    }
                    [viewReMark setAddValue:tv forKey:@"tv"];
                    [viewReMark setAddValue:imageEditorV forKey:@"imageEditorV"];
                    [self setAddValue:viewReMark forKey:@"viewReMark"];
                }
                
            }
            
            
            
            
            
        }else  if ([titleStr isEqualToString:@"标签"]) {
            btn1.hidden=NO;
            tf1.hidden=YES;
            
            
            
            if ([[_DataDic objectForJSONKey:@"sharetype"]isEqualToString:@"1"]) {
                
                [weakview1 setAddValue:@"1" forKey:@"data"];
                [weakbtn1 setTitle:@"自有" forState:UIControlStateNormal];
            }else  if ([[_DataDic objectForJSONKey:@"sharetype"]isEqualToString:@"2"]) {
                
                [weakview1 setAddValue:@"2" forKey:@"data"];
                [weakbtn1 setTitle:@"共享" forState:UIControlStateNormal];
            }
            [btn1 addViewClickBlock:^(UIView *view) {
                [MyUiActionSheet showWithActionSheetBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
                    
                    if (buttonIndex==1) {
                        [weakview1 setAddValue:@"1" forKey:@"data"];
                        [weakbtn1 setTitle:@"自有" forState:UIControlStateNormal];
                    }else if(buttonIndex==2){
                        [weakview1 setAddValue:@"2" forKey:@"data"];
                        [weakbtn1 setTitle:@"共享" forState:UIControlStateNormal];
                    }
                    
                } WithTitle:@"标签" cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"自有",@"共享",nil];
            }];
        }else  if ([titleStr isEqualToString:@"录入者"]) {
            tf1.text=[_DataDic valueForJSONStrKey:@"invitername"];
            tf1.userInteractionEnabled=NO;
        }else  if ([titleStr isEqualToString:@"跟踪者"]) {
            tf1.text=[_DataDic valueForJSONStrKey:@"username"];
            
            tf1.userInteractionEnabled=NO;
            
        }else  if ([titleStr isEqualToString:@"issuccess"]) {
            lb1.hidden=YES;
            btn1.hidden=YES;
            tf1.hidden=YES;
            _btnGroup=[WSButtonGroup new];
            
            {
                
                WSSizeButton*btn1=[RHMethods buttonWithframe:CGRectMake(0, 0, 125, view1.frameHeight) backgroundColor:nil text:@"未成交" font:14 textColor:rgb(51,51,51) radius:0 superview:view1];
                [btn1 setImage:[UIImage imageNamed:@"xkf_checkicon"] forState:UIControlStateNormal];
                [btn1 setImage:[UIImage imageNamed:@"xkf_checkonicon"] forState:UIControlStateSelected];
                [btn1 setBtnImageViewFrame:CGRectMake(10, 12, 16, 16)];
                [btn1 setBtnLableFrame:CGRectMake(34, 0, btn1.frameWidth-34, view1.frameHeight)];
                [_btnGroup addButton:btn1];
            }
            {
                
                WSSizeButton*btn1=[RHMethods buttonWithframe:CGRectMake(125, 0, 125, view1.frameHeight) backgroundColor:nil text:@"已成交" font:14 textColor:rgb(51,51,51) radius:0 superview:view1];
                [btn1 setImage:[UIImage imageNamed:@"xkf_checkicon"] forState:UIControlStateNormal];
                [btn1 setImage:[UIImage imageNamed:@"xkf_checkonicon"] forState:UIControlStateSelected];
                [btn1 setBtnImageViewFrame:CGRectMake(10, 12, 16, 16)];
                [btn1 setBtnLableFrame:CGRectMake(34, 0, btn1.frameWidth-34, view1.frameHeight)];
                [_btnGroup addButton:btn1];
            }
            [_btnGroup setGroupClickBlock:^(WSButtonGroup *group) {
                if (group.currentindex==0) {
                    [view1 setAddValue:@"2" forKey:@"data"];
                }else{
                    
                    [view1 setAddValue:@"1" forKey:@"data"];
                }
            }];
            
            [_btnGroup btnClickAtIndex:0];
            if ([[_DataDic objectForJSONKey:@"issuccess"] isEqualToString:@"1"]) {
                [_btnGroup btnClickAtIndex:1];
            }else  if ([[_DataDic objectForJSONKey:@"issuccess"] isEqualToString:@"2"]) {
                
                [_btnGroup btnClickAtIndex:0];
            }
            
        }else  if ([titleStr isEqualToString:@"重点客户"]) {
            btn1.hidden=YES;
            tf1.hidden=YES;
            UISwitch *switchButton2 = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 51, 30)];
            //            [switchButton2 setOnTintColor:rgbpublicColor];
            [switchButton2 setTag:101];
            [switchButton2 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            [view1 addSubview:switchButton2];
            switchButton2.frameRX=10;
            [switchButton2 beCY];
            switchButton2.onTintColor=rgb(242,200,58);
            
            switchButton2.on=NO;
            [view1 setAddValue:@"1" forKey:@"data"];
            if ([[_DataDic objectForJSONKey:@"level"] isEqualToString:@"1"]) {
                switchButton2.on=NO;
                [view1 setAddValue:@"1" forKey:@"data"];
            }else if ([[_DataDic objectForJSONKey:@"level"] isEqualToString:@"2"]) {
                switchButton2.on=YES;
                [view1 setAddValue:@"2" forKey:@"data"];
                
            }
            
        }else  if ([titleStr isEqualToString:@"报价"]) {
            
            
            tf1.text= [_DataDic objectForJSONKey:@"price"];
            
        }else  if ([titleStr isEqualToString:@"类型"]) {
            
            if (_DataDic) {
                [view1 setAddValue:[_DataDic objectForJSONKey:@"typeid"] forKey:@"data"];
                [btn1 setTitle:[_DataDic objectForJSONKey:@"typename"] forState:UIControlStateNormal];
            }
            
            btn1.hidden=NO;
            tf1.hidden=YES;
            [btn1 addViewClickBlock:^(UIView *view) {
                NSMutableDictionary*mdic=[NSMutableDictionary new];
                [mdic setObject:[NSString stringWithFormat:@"%@",weakbtn1.currentTitle] forKey:@"currentTitle"];
                
                NSMutableArray*mtitlarray=[NSMutableArray new];
                
                NSArray*array=[UTILITY.userTypeData objectForKey:@"types"];
                for (NSDictionary*subdic in array) {
                    //        for (NSDictionary *subdic in [dic objectForJSONKey:@"list"]) {
                    NSMutableDictionary*submdic=[NSMutableDictionary dictionaryWithDictionary:subdic];
                    [submdic setObject:[subdic objectForKey:@"name"] forKey:@"title"];
                    
                    [mtitlarray addObject:submdic];
                    //        }
                }
                [mdic setObject:mtitlarray forKey:@"titleArray"];
                [weakSelf pushController:[SelectTitleViewController class] withInfo:nil withTitle:@"选择分类" withOther:mdic withAllBlock:^(id data, int status, NSString *msg) {
                    //                weaktxtfenlie.text=[data objectForJSONKey:@"title"];
                    [weakbtn1 setTitle:[data objectForJSONKey:@"title"] forState:UIControlStateNormal];
                    [weakview1 setAddValue:[data objectForJSONKey:@"id"] forKey:@"data"];
                    
                    
                }];
                
            }];
        }
        
        //        else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
        //
        //        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
        //
        //        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
        //
        //        }else  if ([arraytitle isEqualToString:@"<#姓名#>"]) {
        //
        //        }
        
        myY=view1.frameYH;;
        
    }
    scrollView.contentHeight=myY;
    kScrollViewCouldScroll(scrollView);
    
}

-(void)switchAction:(id)sender {
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    UIView*view1=[self getAddValueForKey:@"重点客户"];
    
    if (isButtonOn) {
        NSLog(@"开");
        [view1 setAddValue:@"2" forKey:@"data"];
    }else {
        NSLog(@"关");
        [view1 setAddValue:@"1" forKey:@"data"];
    }
}

-(void)reloadScrollView{
      NSArray*  arraytitle=@[@"姓名",@"性别",@"电话",@"微信",@"邮箱",@"性质",@"公司名称",@"分类",@"备注",@"标签",@"录入者",@"跟踪者",@"issuccess",@"重点客户",@"报价",@"类型",];
    float myY=0.0;
    for (int i=0; i<arraytitle.count; i++) {
        UIView*view=[self getAddValueForKey:arraytitle[i]];
        if ([view isKindOfClass:[UIView class]]) {
            
            view.frameY=myY;
            
            myY=view.frameYH;
        }
    }
    
    scrollView.contentHeight=myY;
    kScrollViewCouldScroll(scrollView);
    
}

-(NSString*)getContentWithStr:(NSString*)title{
    UITextField*tf=[[self getAddValueForKey:title] getAddValueForKey:@"tf1"];
    if ([tf isKindOfClass:[UITextField class]]) {
        return tf.text;
    }
    
    return nil;
}
-(NSString*)getDataWithStr:(NSString*)title{
    //    UITextField*tf=[[self getAddValueForKey:title] getAddValueForKey:@"tf1"];
    //    if ([tf isKindOfClass:[UITextField class]]) {
    //        return tf.text;
    //    }
    return [[self getAddValueForKey:title] getAddValueForKey:@"data"];
    return nil;
}


-(void)OKBtnClik:(UIButton*)btn{
    __weak __typeof(self) weakSelf = self;
    
    krequestParam
    if ([self.userInfo isEqualToString:@"买家"]) {
        [dictparam setObject:@"1" forKey:@"type"];
    }else{
        [dictparam setObject:@"0" forKey:@"type"];
    }
    
    
     NSMutableArray * imageArr = [[NSMutableArray alloc]init];
    
    for (int i = 0; i < self.imageArray.count - 1; i ++) {
        
        id image = self.imageArray[i];
        if ([image isKindOfClass:[UIImage class]]) {
            
            [imageArr addObject:image];
            
        }
        
    }
    
    NSMutableArray *fileData = [[NSMutableArray alloc] init];
    for (int i = 0; i < imageArr.count; i++) {
        
        UIImage *image = imageArr[i];
        
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:UIImageJPEGRepresentation([[Utility Share]imageWithImageSimple:image scaledToSize:CGSizeMake(image.size.width, image.size.height)], 1),@"fileData",@"path[]",@"fileKey",@"aa.jpg",@"fileName",@"image",@"fileType", nil];
        
        [fileData addObject:dic];
    }
    
    
    
    if (![[self getContentWithStr:@"姓名"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入姓名"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"姓名"] forKey:@"name"];
    }
    
    if (![[self getDataWithStr:@"性别"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择性别"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"性别"] forKey:@"sex"];
    }
    
    if (![[self getContentWithStr:@"电话"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入电话"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"电话"] forKey:@"mobile"];
    }
    
    if (![[self getContentWithStr:@"微信"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入微信"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"微信"] forKey:@"wechat"];
    }
    
    if (![[self getContentWithStr:@"邮箱"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入邮箱"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"邮箱"] forKey:@"email"];
    }
    
    if (![[self getDataWithStr:@"性质"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择性质"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"性质"] forKey:@"nature"];
    }
    
    if (![[self getContentWithStr:@"公司名称"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入公司名称"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"公司名称"] forKey:@"companyname"];
    }
    
    if (![[self getDataWithStr:@"分类"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入分类"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"分类"] forKey:@"cid"];
    }
    
    
    if (![[self getContentWithStr:@"报价"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入报价"];
        return;
    }else{
        [dictparam setObject:[self getContentWithStr:@"报价"] forKey:@"price"];
    }
  
    
    if (![[self getDataWithStr:@"类型"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请选择类型"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"类型"] forKey:@"typeid"];
    }
    UIButton*btnx=[[self getAddValueForKey:@"备注"] getAddValueForKey:@"btn1"];
    if (btnx.selected) {
        if (![_tv.text notEmptyOrNull]) {
            [SVProgressHUD showErrorWithStatus:@"请填写备注信息"];
            
            return;
        }else{
            [dictparam setAddValue:_tv.text forKey:@"descr"];
//            dataArray=[_imageEditorV getRequsetArrywithkey:@"path" removeServer:NO];;
        }
        
        
    }
    
    
    
    if (![[self getDataWithStr:@"标签"] notEmptyOrNull]) {
        [SVProgressHUD showImage:nil status:@"请输入标签"];
        return;
    }else{
        [dictparam setObject:[self getDataWithStr:@"标签"] forKey:@"sharetype"];
    }
    
    //    if (![[self getContentWithStr:@""] notEmptyOrNull]) {
    //        [SVProgressHUD showImage:nil status:@"请输入录入者"];
    //        return;
    //    }else{
    //        [dictparam setObject:[self getContentWithStr:@"录入者"] forKey:@"<##>"];
    //    }
    //
    //    if (![[self getContentWithStr:@"跟踪者"] notEmptyOrNull]) {
    //        [SVProgressHUD showImage:nil status:@"请输入跟踪者"];
    //        return;
    //    }else{
    //        [dictparam setObject:[self getContentWithStr:@"跟踪者"] forKey:@"<##>"];
    //    }
    
    
//    if (_isEdite) {
        [dictparam setObject:[_DataDic objectForJSONKey:@"id"] forKey:@"id"];
        [dictparam setObject:[_DataDic objectForJSONKey:@"type"] forKey:@"type"];
    
//    }
    
    
    [dictparam setObject:[self getDataWithStr:@"重点客户"] forKey:@"level"];
    [dictparam setObject:[self getDataWithStr:@"issuccess"] forKey:@"issuccess"];
    [dictparam setValue:[self.remArray componentsJoinedByString:@","] forKey:@"pathid"];
    
    [NetEngine uploadAllFileAction:@"customer/updatecustomer" withParams:dictparam fileArray:fileData onCompletion:^(id resData, BOOL isCache) {
        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
            [MyUiIAlertView showAlerttWithTitle:@"温馨提示" message:[resData valueForJSONKey:@"info"] cancelButtonTitle:@"确定" otherButtonTitles:nil WithAlertBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
                [weakSelf backButtonClicked:nil];
                if (weakSelf.allcallBlock) {
                    
                    weakSelf.allcallBlock(nil,200,[resData valueForJSONKey:@"info"]);
                }
            }];
            
        }else{
            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
        }
    } onError:^(NSError *error) {
        
    } withMask:SVProgressHUDMaskTypeBlack];
    
    
}
#pragma mark - 请求数据
-(void)loadDATA{
    krequestParam
    [dictparam setObject:[self.otherInfo objectForJSONKey:@"id"] forKey:@"id"];
    
    [NetEngine createPostAction:@"customer/customer_detail" withParams:dictparam onCompletion:^(id resData, BOOL isCache) {
        if ([[resData getSafeObjWithkey:@"status"] isEqualToString:@"200"]) {
            NSDictionary *dic=[[resData getSafeObjWithkey:@"data"] objectForKey:@"detail"];
            _DataDic=dic;
            
            NSArray * pathArray = [_DataDic[@"path"] mutableCopy];
            self.pathArray = [[NSMutableArray alloc]initWithArray:pathArray];
            _canEdite=![[[resData getSafeObjWithkey:@"data"] objectForKey:@"isedit"] isEqualToString:@"2"];
            [self addView];
            [self addView2];
            [self request];
            [self initNavTopButtons];
            
        }else{
            [SVProgressHUD showErrorWithStatus:[resData valueForJSONKey:@"info"]];
            
        }
    }];
    
}
#pragma mark - 事件监听


#pragma mark - 代理事件
#pragma mark - keyboak
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //注册监听键盘事件
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}

-(void)handleKeyboardDidShow:(NSNotification *)notification{
    
    NSDictionary *info = [notification userInfo];
    CGRect keyboardFrame;
    [[info objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    CGFloat distanceToMove = kbSize.height;
    NSLog(@"---->动态键盘高度:%f",distanceToMove);
#pragma mark zxh UI布局 根据键盘布局
    
    if (![self getAddValueForKey:@"scrollViewH"]) {
        [self setAddValue:[NSString stringWithFormat:@"%f",scrollView.frameHeight] forKey:@"scrollViewH"];
    }
    
    scrollView.frame=CGRectMake(X(scrollView), Y(scrollView), W(scrollView),[[self getAddValueForKey:@"scrollViewH"] floatValue]-distanceToMove+44);
    
    [WSKeyBoardTool TFscrollview:scrollView];
    _viewlastInput.frameBY=distanceToMove;
}
- (void)handleKeyboardWillHide:(NSNotification *)notification
{
    
    [UIView animateWithDuration:0.3 animations:^{
        scrollView.frame=CGRectMake(0,  Y(scrollView), kScreenWidth,[[self getAddValueForKey:@"scrollViewH"] floatValue]);
        _viewlastInput.frameBY=0;
    }];
}//
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

#pragma mark - textfielddelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    if (textField==_transRecordTf) {
        [self addTransRecord:nil];
    }
    [self.view endEditing:YES];
    return YES;
}

#pragma mark - UITextView Delegate Methods
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
#pragma mark  单击后键盘消失
-(void)tapView
{
    //    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    //    // 连续敲击2次,手势才能识别成功
    //    tap.numberOfTapsRequired = 1;
    //    tap.numberOfTouchesRequired = 1;
    //
    //    // 2.添加手势识别器对象到对应的view
    //    [self.view addGestureRecognizer:tap];
    //
    //    // 3.添加监听方法(识别到了对应的手势,就会调用监听方法)
    //    [tap addTarget:self action:@selector(tapView)];
    
    
    [self.view endEditing:YES];
}

#pragma mark  tableview网络请求
-(void)request{
    krequestParam
    
    [dictparam setObject:@"%@" forKey:@"page"];
    [dictparam setObject:@"20" forKey:@"pagesize"];
    [dictparam setObject:[self.otherInfo objectForJSONKey:@"id"] forKey:@"cuid"];
    //    [dictparam setObject:@"products" forKey:@"type"];
  
    [_mtableView showRefresh:YES LoadMore:YES];
    _mtableView.urlString=[NSString stringWithFormat:@"customer/tracklist%@",dictparam.wgetParamStr];
    [_mtableView refresh];
    
    
}
#pragma mark - 按钮事件监听


#pragma mark - 代理事件



#pragma mark -  tableview代理方法
- (NSInteger)numberOfSectionsInTableView:(RHTableView *)tableView{
    
    
    return 1;
    
}

-(NSInteger)tableView:(RHTableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    return tableView.dataArray.count;
}

-(CGFloat)tableView:(RHTableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0;
}
-(CGFloat)tableView:(RHTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary*dic=tableView.dataArray[indexPath.row];
    
    NSArray*arraytitle=[dic objectForJSONKey:@"path"];
    if (!arraytitle.count) {
        
        NSString*celltitle=[dic objectForJSONKey:@"descr"];
        return [celltitle HEIGHTwF:12 W:kScreenWidth-10-58]+20+14+20;
        
    }else{
        float mywith= (kScreenWidth-40-58-20)/3.0;
        
  return  (arraytitle.count-1)/3*(mywith+10)+20+14+10+mywith;
    }
    return 95;
}
-(CGFloat)tableView:(RHTableView *)tableView heightForFooterInSection:(NSInteger)section    {
    
    return 0.000;
}

-(UIView *)tableView:(RHTableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return [UIView new];
    
    
}

#pragma mark  cell处理
- (UITableViewCell *)tableView:(RHTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(tableView ==_mtableView){
        //
        UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone ;
            cell.frameWidth=tableView.frameWidth;
            cell.backgroundColor=zrgbwhiteColor;
            UIView*viewline=[RHMethods viewWithFrame:CGRectMake(29, 0, 1, 100) backgroundcolor:rgb(220,220,220) superView:cell];
            
            UIImageView*imgVIcon=[RHMethods imageviewWithFrame:CGRectMake(12, 20, 35, 35) defaultimage:@"icon" supView:cell];
            [imgVIcon beRound];
//            imgVIcon.backgroundColor=zrgborenge;
            UILabel*lbtime=[RHMethods lableX:58 Y:imgVIcon.frameY W:kScreenWidth-10-58 Height:14 font:14 superview:cell withColor:nil text:@"2017-7-24 13:20"];
            UILabel*lbtitle=[RHMethods lableX:lbtime.frameX Y:lbtime.frameYH+10 W:lbtime.frameWidth Height:0 font:12 superview:cell withColor:rgb(153,153,153) text:@"具体时间下午开会确认具体时间下午开会确认具体时间下午开会确认具体时间下午开会确认"];
            
            UIView*viewImage=[RHMethods viewWithFrame:CGRectMake(lbtime.frameX, lbtime.frameYH+10, lbtime.frameWidth, 0) backgroundcolor:nil superView:cell];
            
            [cell setAddValue:viewline forKey:@"viewline"];
            [cell setAddValue:imgVIcon forKey:@"imgVIcon"];
            [cell setAddValue:lbtime forKey:@"lbtime"];
            [cell setAddValue:lbtitle forKey:@"lbtitle"];
            [cell setAddValue:viewImage forKey:@"viewImage"];
            //初始每行数组容器
            [self.imageViewArr addObject:[[NSMutableArray alloc]init]];
            
        }
        UILabel*viewline=[cell getAddValueForKey:@"viewline"];
        UILabel*imgVIcon=[cell getAddValueForKey:@"imgVIcon"];
        UILabel*lbtime=[cell getAddValueForKey:@"lbtime"];
        UILabel*lbtitle=[cell getAddValueForKey:@"lbtitle"];
        UILabel*viewImage=[cell getAddValueForKey:@"viewImage"];
        NSDictionary*dic=tableView.dataArray[indexPath.row];
        NSString*celltitle=[dic objectForJSONKey:@"descr"];
        [imgVIcon imageWithURL:[dic objectForJSONKey:@"userpath"] defaultImage:nil];
        
        lbtime.text=[dic objectForJSONKey:@"ctime"];
        lbtitle.text=celltitle;
        lbtitle.hidden=YES;
        viewImage.hidden=YES;
        
        
          NSArray*arraytitle=[dic objectForJSONKey:@"path"];
        if (!arraytitle.count) {
            lbtitle.hidden=NO;
            lbtitle.frameHeight=[celltitle HEIGHTwF:12 W:kScreenWidth-10-58];
            viewline.frameHeight=lbtitle.frameHeight+20+14+20;
            
        }else{
            
            viewImage.hidden=NO;
            float mywith= (kScreenWidth-40-58-20)/3.0;
            
            for (UIView*view in viewImage.subviews) {
                view.hidden=YES;
            }
            //拿出本行的图片数组
            NSMutableArray * arr = self.imageViewArr[indexPath.row];
//            //清空重复的
            [arr removeAllObjects];
            for (int i=0; i<arraytitle.count; i++) {
                UIImageView*imgV1=[viewImage getAddValueForKey:[NSString stringWithFormat:@"%d",i]];
                if (imgV1==nil) {
                    EMWeakSelf(weakSelf);
                   imgV1= [RHMethods imageviewWithFrame:CGRectMake(i%3*(mywith+10), i/3*(mywith+10), mywith, mywith) defaultimage:@"icon" supView:viewImage];
                    [imgV1 addViewClickBlock:^(UIView *view) {
                       //看大图
                        [Utility showBigImage:weakSelf.imageViewArr[indexPath.row] clickIndex:i viewContent:weakSelf type:@"2"];
                        
                        
                    }];
                    [viewImage setAddValue:imgV1 forKey:[NSString stringWithFormat:@"%d",i]];
                    
//                    imgV1.backgroundColor=zrgborenge;
                }
               
                //添加本行数组
                [arr addObject:imgV1];
                [imgV1 imageWithURL:arraytitle[i] defaultImage:nil];
                viewImage.frameHeight=imgV1.frameYH+10;
                imgV1.hidden=NO;
            }
            
            viewline.frameHeight= (arraytitle.count-1)/3*(mywith+10)+20+14+10+mywith;
        }
        
        
        
        return cell;
        
    }
        return [UITableViewCell new];
}
#pragma mark  选中cell
-(void)tableView:(RHTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dic=tableView.dataArray[indexPath.row];
    

}
-(void)backButtonClicked:(id)sender{
    
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"CRMList" object:nil];
    
    
    [super backButtonClicked:sender];
}
-(NSMutableArray *)imageViewArr{
    
    if (!_imageViewArr) {
        
        _imageViewArr = [[NSMutableArray alloc]init];
        
        
    }
    
    return _imageViewArr;
}
-(NSMutableArray *)imageArray{
    
    if (!_imageArray) {
        
        _imageArray = [[NSMutableArray alloc]init];
    }
    
    return _imageArray;
}
-(NSMutableArray *)pathArray{
    
    if (!_pathArray) {
        
        _pathArray = [[NSMutableArray alloc]init];
    }
    
    return _pathArray;
}
-(NSMutableArray *)remArray{
    
    if (!_remArray) {
        
        _remArray = [[NSMutableArray alloc]init];
    }
    
    return _remArray;
}
@end
